package com.kuang.controller.pfsi;

import com.kuang.pojo.AstControllerHeart;
import com.kuang.pojo.pfsi.AstPfsiDeviceOpen;
import com.kuang.service.asset.AstControllerHeartService;
import com.kuang.service.pfsi.AstPfsiDeviceOpenService;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
@Log4j
public class AstPfsiDeviceOpenController {

    @Resource
    AstPfsiDeviceOpenService astPfsiDeviceOpenService;

    /**
     * 获取设备心跳数据
     * @param model
     * @return
     */
    @RequestMapping("getAstPfsiDeviceOpens")
    public String getAstPfsiDeviceOpens(Model model){
        List<AstPfsiDeviceOpen> astPfsiDeviceOpens = astPfsiDeviceOpenService.selectAll();
        model.addAttribute("datas",astPfsiDeviceOpens);
        model.addAttribute("device_code","");
        model.addAttribute("ver","");
        return "pfsi/ast_pfsi_device_open_list";
    }

    /**
     * 获取设备心跳数据通过条件
     * @param model
     * @return
     */
    @PostMapping("getAstPfsiDeviceOpensByExample")
    public String getAstPfsiDeviceOpensByExample(AstPfsiDeviceOpen astPfsiDeviceOpen,Model model){
        List<AstPfsiDeviceOpen> astPfsiDeviceOpens = astPfsiDeviceOpenService.selectAllByExample(astPfsiDeviceOpen);
        model.addAttribute("datas",astPfsiDeviceOpens);
        model.addAttribute("device_code",astPfsiDeviceOpen.getDevice_code());
        model.addAttribute("ver",astPfsiDeviceOpen.getVer());
        return "pfsi/ast_pfsi_device_open_list";
    }

    /**
     * 获取设备信息通过id
     * @param model
     * @return
     */
    @RequestMapping("getAstPfsiDeviceOpensById/{id}")
    public String getAstPfsiDeviceOpensById(@PathVariable("id") String id, Model model){
        AstPfsiDeviceOpen astPfsiDeviceOpen = new AstPfsiDeviceOpen();
        astPfsiDeviceOpen.setAst_pfsi_device_open_id(id);
        List<AstPfsiDeviceOpen> astPfsiDeviceOpens = astPfsiDeviceOpenService.selectAllByExample(astPfsiDeviceOpen);
        model.addAttribute("data",astPfsiDeviceOpens.get(0));
        return "pfsi/ast_pfsi_device_open_from";
    }

}
